<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Victor
 * Date: 07.12.11
 * Time: 0:14
 * To change this template use File | Settings | File Templates.
 */
 
class Course_Course extends Core_BaseModel{

    public function getCoursesByCategory($categoryId){

        $pdo = $this->dataModule->getConnection();
        $sql = "SELECT `idcourse`,`courseName` FROM `dzundza_course`
        where `category_idcategory` = :categoryid";
        $stn = $pdo->prepare($sql);
        $stn->bindParam(':categoryid',$categoryId,PDO::PARAM_INT);
        $stn->execute();
        $result = $stn->fetchAll(PDO::FETCH_ASSOC);
        /*
        $array = array();
        foreach($result as $key => $value){
           $array[$value['idCategory']] = $value['categoryName'];
               }
        */
        return $result;
    }

    public function getCourseNameByID($idCourse)
    {
        $courseName = null;
        $pdo = $this->dataModule->getConnection();
        $sql = "SELECT `courseName` FROM `dzundza_course` where `idcourse` = :id";
        $stn = $pdo->prepare($sql);
        $stn->bindParam(':id',$idCourse,PDO::PARAM_INT);
        $stn->execute();
        $result = $stn->fetch(PDO::FETCH_COLUMN);
        if($result != false) $courseName = $result;
        return $courseName;
    }

}
